import { createI18n } from "vue-i18n";
import store from "@/store";
import ch from "./ch/index";
import en from "./en/index";
// 注册i8n实例并引入语言文件
const i18nObj = {
  locale: getLanguageType(),
  messages: {
    zh: ch,
    en: en
  }
}

function getLanguageType():string {
  let lang:string = localStorage.getItem('lang') || "zh"
  const type:string = navigator?.appName;
  if (type == "Netscape") {
    lang = navigator.language||"zh"
  }
  lang = lang.substring(0, 2);//获取浏览器配置语言前两位
  if(lang == "zh"){
    lang = "zh"
  }else{
    lang = "en"
  }
  localStorage.setItem("lang",lang);
  store.commit("setCurrentLanguage",lang)
  return lang
}
getLanguageType()

export default createI18n(i18nObj)